class StudentManage:
    def __init__(self):
        self.students = {
            'zr': {
                'course': 'python',
                'score': 99
            },
            'zrr': {
                'course': 'python',
                'score': 88
            }
        }

    def add_student(self):
        print('添加学生')
        name, course, score = input('输入学生的姓名、课程、成绩，用空格隔开:').split()
        if not name or not course or not score:
            print('输入错误')
            return
        elif name in self.students:
            print('学生已存在')
        else:
            self.students[name] = {
                'course': course,
                'score': int(score)
            }

    def check_student(self):
        print('查询学生')
        while True:
            name = input('请输入学生姓名:')
            if name not in self.students:
                print('学生不存在，请重新输入')
            else:
                print(name, '课程:', self.students[name]['course'], '分数:',
                      self.students[name]['score'])
                break

    def update_student(self):
        print('更新学生成绩')
        name = input('请输入学生姓名:')
        if name not in self.students:
            print('学生不存在')
        else:
            print(name, '课程:', self.students[name]['course'], '分数:', self.students[name]['score'])
            while True:
                score = input('请输入新成绩')
                if score.isdigit():
                    self.students[name]['score'] = int(score)
                    print('成绩已更新')
                    print(name, '课程:', self.students[name]['course'], '分数:',
                          self.students[name]['score'])
                    break
                else:
                    print('非法数字')

    def delete_student(self):
        print('删除学生')
        while True:
            name = input('请输入要删除的学生姓名:')
            if name not in self.students:
                print('学生不存在,请重新输入:')
            else:
                del self.students[name]
                print('学生已删除，当前系统中人数:', len(self.students))
                break

    def show_all_students(self):
        for key, value in self.students.items():
            print(f'姓名:{key:<5}', f'课程:{value['course']:<10}', f'成绩:{value['score']:<5}')

    def show_functions(self):
        while True:
            print('-----学生系统首页-----')
            print('1 -- 添加学生成绩')
            print('2 -- 查询学生成绩')
            print('3 -- 更新学生成绩')
            print('4 -- 删除学生成绩记录')
            print('5 -- 显示所有学生成绩')
            print('6 -- 退出系统')
            choice = input('Enter your choice: ')
            print('-' * 15)
            if choice == '1':
                self.add_student()
            elif choice == '2':
                self.check_student()
            elif choice == '3':
                self.update_student()
            elif choice == '4':
                self.delete_student()
            elif choice == '5':
                self.show_all_students()
            elif choice == '6':
                break
            else:
                print('Invalid choice')
        print('系统关闭')


if __name__ == '__main__':
    StudentManage().show_functions()
